package com.egao.texasHoldEmPoker.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.texasHoldEmPoker.entity.Player;
import com.egao.texasHoldEmPoker.service.PlayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 玩家
 * @author : Doman
 * @date : 2022-01-26 12:39:41
 * @version ：1.0
 */

@Api(tags = "玩家")
@RestController
@RequestMapping("/api/texasHoldEmPoker/player")
public class PlayerController extends BaseController {

	@Autowired
	private PlayerService playerService;

	/**
	 * 分页查询列表
	 */
//	@PreAuthorize("hasAuthority('texasHoldEmPoker:player:list')")
    //@OperLog(value = "玩家", desc = "分页查询")
    @ApiOperation(value ="分页查询玩家",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "deskId:desk id\n" +
        "wechatCode:wecha code\n" +
        "wechatName:nick name\n" +
        "poker5:牌5\n" +
        "poker6:牌6\n" +
        "state:0 正常 1离席\n" +
        "fold:0 正常 1弃牌\n" +
        "indebted:负债\n" +
        "faceValue:面值\n" +
        "winPrice:能赚的钱\n" +
        "remark:备注\n" +
        "orderNum:排序\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Player player) throws Exception{
        return playerService.list(page, player, getLoginUser());
    }

    /**
     * 查询全部玩家
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:player:list')")
    //@OperLog(value = "玩家", desc = "查询全部")
    @ApiOperation("查询全部玩家")
    @GetMapping()
    public JsonResult list(Player player){
        return playerService.list(player, getLoginUser());
    }

    /**
     * 根据id查询玩家
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:player:list')")
    //@OperLog(value = "玩家", desc = "根据id查询")
    @ApiOperation("根据id查询玩家")
    @GetMapping("/get")
    public JsonResult get(Player player) {
        return playerService.getById(player);
		// 使用关联查询
        //PageParam<player> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<player> records = playerService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加玩家
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:player:save')")
    @OperLog(value = "玩家", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加玩家",notes = "" +
            "deskId:desk id\n" +
            "wechatCode:wecha code\n" +
            "wechatName:nick name\n" +
            "poker5:牌5\n" +
            "poker6:牌6\n" +
            "state:0 正常 1 离席\n" +
            "indebted:负债\n" +
            "faceValue:面值\n" +
            "winPrice:能赚的钱\n" +
            "remark:备注\n" +
            "orderNum:排序\n" +
        "",httpMethod = "POST")
    @PostMapping()
    public JsonResult save(Player player) {
        return playerService.save(player, getLoginUser());
    }

    /**
     * 修改玩家
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:player:update')")
    @OperLog(value = "玩家", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改玩家",notes = "" +
            "id:id\n" +
            "deskId:desk id\n" +
            "wechatCode:wecha code\n" +
            "wechatName:nick name\n" +
            "poker5:牌5\n" +
            "poker6:牌6\n" +
            "state:0 正常 1 离席\n" +
            "fold:0 正常 1弃牌\n" +
            "indebted:负债\n" +
            "faceValue:面值\n" +
            "winPrice:能赚的钱\n" +
            "remark:备注\n" +
            "orderNum:排序\n" +
        "",httpMethod = "PUT")
    @PutMapping()
    public JsonResult update(Player player) {
        return playerService.update(player, getLoginUser());
    }

    /**
     * 删除玩家
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:player:remove')")
    @OperLog(value = "玩家", desc = "删除", result = true)
    @ApiOperation(value ="删除玩家",notes = "" +
      "id:id\n" +
      "",httpMethod = "POST")
    @DeleteMapping("/remove")
    public JsonResult remove(Player player ) {
        return playerService.remove(player, getLoginUser());
    }

    /**
     * 批量添加玩家
     */
    /**@RequiresPermissions("texasHoldEmPoker:player:save")
    @OperLog(value = "玩家", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Player> list) {
        if (playerService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改玩家
     */
    /**@RequiresPermissions("texasHoldEmPoker:player:update")
    @OperLog(value = "玩家", desc = "批量修改", result = true)
    @ResponseBody
    @PutMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Player> batchParam) {
        if (batchParam.update(playerService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除玩家
     */
    /**@RequiresPermissions("texasHoldEmPoker:player:remove")
    @OperLog(value = "玩家", desc = "批量删除", result = true)
    @ResponseBody
    @DeleteMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (playerService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
